﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Text;
using System.Windows.Forms;
using System.Collections;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Threading;
using System.IO;

namespace INSAForManagers
{
    public partial class FormWorkMultiSum : Form
    {
        private DataTable tbl = null;
        private ArrayList colNames = new ArrayList();
        
        //변경사항저장 여부
        public static bool isSavedChange = true;

        private FormMain parent;

        
        public FormWorkMultiSum(FormMain p)
        {
            InitializeComponent();

            Control.CheckForIllegalCrossThreadCalls = false;

            parent = p;            
            tbl = new DataTable();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            if (isSavedChange == true)
            {
                tbl.Dispose();

                FormMain.setMnuSWorkMultiSumEnabled();
                parent.stateRefresh();
                this.Close();
            }
            else
            {
                MessageBox.Show("변동 사항이 있습니다. 저장하십시오.    ", "확인", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void addGridViewColumns()
        {
            DataColumn col;

            int valuer_num = Config.ValuerList.Count;

            //연번
            col = new DataColumn();
            col.DataType = Type.GetType("System.Int32");
            col.ColumnName = "연번";
            colNames.Add("연번");
            col.AllowDBNull = false;
            col.ReadOnly = true;
            tbl.Columns.Add(col);

            //소속
            col = new DataColumn();
            col.DataType = Type.GetType("System.String");
            col.ColumnName = "소속";
            colNames.Add("소속");
            col.AllowDBNull = false;
            col.ReadOnly = true;
            tbl.Columns.Add(col);

            //개인번호
            col = new DataColumn();
            col.DataType = Type.GetType("System.String");
            col.ColumnName = "개인번호";
            colNames.Add("개인번호");
            col.AllowDBNull = false;
            col.ReadOnly = true;
            tbl.Columns.Add(col);

            //평가자 대상자 성명
            col = new DataColumn();
            col.DataType = Type.GetType("System.String");
            col.ColumnName = "평가대상자";
            colNames.Add("평가대상자");
            col.AllowDBNull = false;
            col.ReadOnly = true;
            tbl.Columns.Add(col);

            //평정자
            col = new DataColumn();
            col.DataType = Type.GetType("System.Double");
            col.ColumnName = "평정자(30)";
            colNames.Add("평정자(30)");
            col.AllowDBNull = true;
            col.ReadOnly = false;
            tbl.Columns.Add(col);

            //확인자
            col = new DataColumn();
            col.DataType = Type.GetType("System.Double");
            col.ColumnName = "확인자(40)";
            colNames.Add("확인자(40)");
            col.AllowDBNull = true;
            col.ReadOnly = false;
            tbl.Columns.Add(col);

            //다면평가
            col = new DataColumn();
            col.DataType = Type.GetType("System.Double");
            col.ColumnName = "다면평가(30)";
            colNames.Add("다면평가(30)");
            col.AllowDBNull = true;
            col.ReadOnly = false;
            tbl.Columns.Add(col);

            //총점
            col = new DataColumn();
            col.DataType = Type.GetType("System.Double");
            col.ColumnName = "총점";
            colNames.Add("총점");
            col.AllowDBNull = true;
            col.ReadOnly = false;
            tbl.Columns.Add(col);

            //감점
            col = new DataColumn();
            col.DataType = Type.GetType("System.Double");
            col.ColumnName = "감점";
            colNames.Add("감점");
            col.AllowDBNull = true;
            col.ReadOnly = false;
            tbl.Columns.Add(col);

            //조정점
            col = new DataColumn();
            col.DataType = Type.GetType("System.Double");
            col.ColumnName = "조정점";
            colNames.Add("조정점");
            col.AllowDBNull = true;
            col.ReadOnly = false;
            tbl.Columns.Add(col);

            //순위
            col = new DataColumn();
            col.DataType = Type.GetType("System.Int32");
            col.ColumnName = "순위";
            colNames.Add("순위");
            col.AllowDBNull = true;
            col.ReadOnly = false;
            tbl.Columns.Add(col);


            dgvWMSum.DataSource = tbl;


        }

        private void FormWorkMultiSum_Load(object sender, EventArgs e)
        {
            try
            {
                addGridViewColumns();

                dgvWMSum.Columns[0].Visible = false;
                dgvWMSum.Columns[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                dgvWMSum.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                dgvWMSum.Columns[1].Width = 130;
                dgvWMSum.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                dgvWMSum.Columns[2].Visible = false;
                dgvWMSum.Columns[3].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                dgvWMSum.Columns[4].DefaultCellStyle.Format = "#0.000";
                dgvWMSum.Columns[4].Width = 80;
                dgvWMSum.Columns[4].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                dgvWMSum.Columns[5].DefaultCellStyle.Format = "#0.000";
                dgvWMSum.Columns[5].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                dgvWMSum.Columns[5].Width = 80;
                dgvWMSum.Columns[6].DefaultCellStyle.Format = "#0.000";
                dgvWMSum.Columns[6].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                dgvWMSum.Columns[6].Width = 80;
                dgvWMSum.Columns[7].DefaultCellStyle.Format = "#0.000";
                dgvWMSum.Columns[7].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                dgvWMSum.Columns[7].Width = 80;
                dgvWMSum.Columns[8].DefaultCellStyle.Format = "#0.000";
                dgvWMSum.Columns[8].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                dgvWMSum.Columns[8].Width = 80;
                dgvWMSum.Columns[9].DefaultCellStyle.Format = "#0.000";
                dgvWMSum.Columns[9].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                dgvWMSum.Columns[9].Width = 80;
                dgvWMSum.Columns[10].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                dgvWMSum.Columns[10].Width = 80;

                initGridView();

                dgvWMSum.Columns[10].DefaultCellStyle.BackColor = Color.LightBlue;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

                        
        }

        private void initGridView()
        {
            //기존 행 지우기
            tbl.Rows.Clear();

            //기존 합산정보가 없으면
            ArrayList list;

            if (DBUtil.isExistedWorkMultiInfo(getTargetType()) == false)
            {
                list = DBUtil.getWorkControlTargetsInfo(getTargetType());
            }
            else
            {
                list = DBUtil.getWorkMultiTargetsInfo(getTargetType());
            }

            int nRow = 1;
            foreach (ArrayList tmp in list)
            {
                DataRow row = tbl.NewRow();
                row[0] = nRow;
                row[1] = DBUtil.getOrganName(Config.Mvi.Organ);
                row[2] = tmp[0];
                row[3] = DBUtil.getMTargetName(tmp[0].ToString());

                double item1 = DBUtil.getWorkEvaluePoint("0", tmp[0].ToString()) * 0.3;
                double item2 = DBUtil.getWorkEvaluePoint("1", tmp[0].ToString()) * 0.4;
                double item3 = DBUtil.getMultiPoint(tmp[0].ToString()) * 0.3;

                if (item1 < 1.0 || item2 < 1.0 || item3 < 1.0)
                {
                    btnCalc.Enabled = false;
                    btnDemerit.Enabled = false;
                    lblMsg.Text = "*일부 평정 요소가 누락되었습니다. 확인하십시오.";
                    lblMsg.ForeColor = Color.FromArgb(239, 37, 61);
                }

                row[4] = item1;
                row[5] = item2;
                row[6] = item3;

                row[7] = item1 + item2 + item3;
                ArrayList demerit = DBUtil.getDemeritInfo(tmp[0].ToString());
                double demeritPoint = 0.0;
                double originalPoint = 0.0;
                double changePoint = 0.0;
                double resultPoint = DBUtil.getWorkMultiSumValue1(tmp[0].ToString());
                if (demerit.Count > 0)
                {
                    demeritPoint = Double.Parse(demerit[2].ToString());
                    originalPoint = Double.Parse(demerit[1].ToString());
                    changePoint = Double.Parse(demerit[3].ToString());
                    if (changePoint != resultPoint)
                    {
                        resultPoint = changePoint;                        
                    }
                }
                row[8] = demeritPoint;
                row[9] = resultPoint;                
                row[10] = DBUtil.getWorkMultiSumValue2(tmp[0].ToString());
                tbl.Rows.Add(row);
                                
                nRow++;
            }

            dgvWMSum.DataSource = tbl;            
        }

        private void btnCalc_Click(object sender, EventArgs e)
        {
            btnCalc.Enabled = false;

            calcRank();
        }


        private void calcRank() {

            int targetCount = DBUtil.getMTargetCount(getTargetType());
            try
            {
                if (dgvWMSum.Rows.Count == 0)
                {
                    lblMsg.Text = "*대상자가 없습니다.";
                    return;
                }

                initGridView();

                dgvWMSum.Columns[7].SortMode = DataGridViewColumnSortMode.Programmatic;
                dgvWMSum.Sort(dgvWMSum.Columns[7], ListSortDirection.Descending);

                double[] total = new double[targetCount];

                //총점
                for (int i = 0; i < targetCount; i++)
                {
                    total[i] = Math.Round(Double.Parse(dgvWMSum.Rows[i].Cells[7].Value.ToString()), 3);
                    
                }

                int[] index = Util.existedSamePoint(total);
                if (index[0] != 0)
                {
                    MessageBox.Show("총점" + total[index[0]] + "에 동점이 존재합니다.    \n\n근무성적평정에서 배점을 다시 하시기 바랍니다.    ", "확인", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    btnCalc.Enabled = true;
                    return;
                }
                
                //순위
                for (int i = 0; i < DBUtil.getMTargetCount(getTargetType()); i++)
                {
                    dgvWMSum.Rows[i].Cells[10].Value = Util.getSortNum(total, total[i]);
                }
                

                //조정점
                ArrayList num = DBUtil.getRatioNum(getTargetType());
                int su_num = (Int16)num[0];
                int wo_num = (Int16)num[1];
                int mi_num = (Int16)num[2] + (Int16)num[3];

                int chk = 1;//평어별 인원 카운트
                string lang = "수";
                int chknum = su_num;
                for (int i = 1; i <= DBUtil.getMTargetCount(getTargetType()); i++)
                {
                    if (i == su_num + 1)
                    {
                        lang = "우";
                        chk = 1;
                        chknum = wo_num;
                    }
                    else if (i == su_num + wo_num + 1)
                    {
                        lang = "미";
                        chk = 1;
                        chknum = mi_num;
                    }

                    //조정점
                    dgvWMSum.Rows[i - 1].Cells[9].Value = DBUtil.getWorkControlPoint(lang, chk, chknum);


                    chk++;
                }

                //변동 사항 저장 여부 변경
                isSavedChange = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvWMSum.Rows[0].Cells[10].Value.ToString().Equals(""))
                {
                    lblMsg.Text = "*순위 계산을 먼저하신 후 저장하세요!";
                    return;
                }
                for (int i = 0; i < DBUtil.getMTargetCount(getTargetType()); i++)
                {
                    ArrayList list = new ArrayList();
                    list.Add(dgvWMSum.Rows[i].Cells[2].Value);
                    list.Add(dgvWMSum.Rows[i].Cells[4].Value);
                    list.Add(dgvWMSum.Rows[i].Cells[5].Value);
                    list.Add(dgvWMSum.Rows[i].Cells[6].Value);
                    list.Add(dgvWMSum.Rows[i].Cells[7].Value);
                    list.Add(dgvWMSum.Rows[i].Cells[9].Value);
                    list.Add(dgvWMSum.Rows[i].Cells[10].Value);
                    DateTime now = DateTime.Now;
                    list.Add(now);

                    DBUtil.writeWorkMultiInfo(list);
                }

                //변동 사항 저장 여부 변경
                isSavedChange = true;
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            MessageBox.Show("저장하였습니다.    ", "확인", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void btnXls_Click(object sender, EventArgs e)
        {
            Thread t = new Thread(new ThreadStart(printXls));
            t.Start();
        }

        private void printXls()
        {
            try
            {
                if (dgvWMSum.Rows.Count < 2)
                {
                    lblMsg.Text = "평정 및 확인 후 다시 시도하십시오.";
                    Util.closeXls();
                    return;
                }

                btnXls.Enabled = false;

                lblMsg.Text = "인쇄 준비중입니다...";

                Util.openXls(Application.StartupPath + "\\WorkEvalueSum");

                //평정기간설정
                Excel.Range range = Util.OSheet.get_Range("A3", Missing.Value);
                range.set_Value(Missing.Value, Config.Mvi.SDate);

                range = Util.OSheet.get_Range("A4", Missing.Value);
                range.set_Value(Missing.Value, Config.Mvi.EDate);

                //확인자
                range = Util.OSheet.get_Range("K3", Missing.Value);
                range.set_Value(Missing.Value, "교장");

                range = Util.OSheet.get_Range("K4", Missing.Value);
                range.set_Value(Missing.Value, Config.Mvi.Confirmer);

                //평정자
                range = Util.OSheet.get_Range("N3", Missing.Value);
                range.set_Value(Missing.Value, "교감");

                range = Util.OSheet.get_Range("N4", Missing.Value);
                range.set_Value(Missing.Value, Config.Mvi.Evaluer1 + "," + Config.Mvi.Evaluer2);

                //다면평가합산 테이블에서 순위 오름 차순으로 pcode호출
                int rowIndex = 13;

                ArrayList ratio = DBUtil.getRatioNum(getTargetType());
                int su = Int32.Parse(ratio[0].ToString());
                int wo = Int32.Parse(ratio[1].ToString());
                int mi = Int32.Parse(ratio[2].ToString());
                int ya = Int32.Parse(ratio[3].ToString());

                ArrayList list = DBUtil.getMTargetFromWorkEvalueSum(getTargetType());

                if (list.Count == 0)
                {
                    lblMsg.Text = "순위계산을 한 다음 저장 후 다시 시도하세요.";
                    Util.closeXls();
                    return;
                }

                for (int i = 0; i < list.Count; i++)
                {
                    lblMsg.Text = DBUtil.getMTargetName(list[i].ToString()) + " 인쇄 데이터 수집 중...";

                    //소속
                    range = Util.OSheet.get_Range("A" + rowIndex.ToString(), Missing.Value);
                    range.set_Value(Missing.Value, DBUtil.getOrganName(Config.Mvi.Organ));

                    //성명
                    range = Util.OSheet.get_Range("B" + rowIndex.ToString(), Missing.Value);
                    string name = DBUtil.getMTargetName(list[i].ToString());
                    if (DBUtil.getSameNameExist(name)) name = name + "(" + DBUtil.getMTargetInfo(list[i].ToString())[2].ToString() + ")";
                    range.set_Value(Missing.Value, name);

                    //근무성적평정
                    range = Util.OSheet.get_Range("D" + rowIndex.ToString(), Missing.Value);
                    range.set_Value(Missing.Value, "근무성적\n평정");

                    //평정자
                    range = Util.OSheet.get_Range("E" + rowIndex.ToString(), Missing.Value);
                    range.set_Value(Missing.Value, "평정자");

                    //확인자
                    range = Util.OSheet.get_Range("E" + (rowIndex + 1).ToString(), Missing.Value);
                    range.set_Value(Missing.Value, "확인자");

                    //다면평가
                    range = Util.OSheet.get_Range("D" + (rowIndex + 2).ToString(), Missing.Value);
                    range.set_Value(Missing.Value, "다면평가");

                    //합산표 정보
                    ArrayList suminfo = DBUtil.getWorkMultiSumInfo(list[i].ToString());


                    //평정자
                    range = Util.OSheet.get_Range("F" + rowIndex.ToString(), Missing.Value);
                    range.set_Value(Missing.Value, Double.Parse(suminfo[2].ToString()).ToString("#0.000"));

                    //확인자
                    range = Util.OSheet.get_Range("F" + (rowIndex + 1).ToString(), Missing.Value);
                    range.set_Value(Missing.Value, Double.Parse(suminfo[3].ToString()).ToString("#0.000"));

                    //다면평가
                    range = Util.OSheet.get_Range("F" + (rowIndex + 2).ToString(), Missing.Value);
                    range.set_Value(Missing.Value, Double.Parse(suminfo[4].ToString()).ToString("#0.000"));

                    //총점
                    range = Util.OSheet.get_Range("G" + rowIndex.ToString(), Missing.Value);
                    range.set_Value(Missing.Value, Double.Parse(suminfo[5].ToString()).ToString("#0.000"));

                    //조정점
                    range = Util.OSheet.get_Range("J" + rowIndex.ToString(), Missing.Value);
                    string strTmp = Double.Parse(suminfo[6].ToString()).ToString("#0.000");
                    if (DBUtil.existedDemeritData(list[i].ToString()))
                    {
                        strTmp += "\n(" + Double.Parse(DBUtil.getDemeritInfo(list[i].ToString())[1].ToString()).ToString("#0.000") + ")";
                    }
                    string sGrade = "";
                    if (i < su)
                    {
                        sGrade = "수";
                    }
                    else if (i >= su && i < su + wo)
                    {
                        sGrade = "우";
                    }
                    else if (i >= su + wo && i < su + wo + mi + ya)
                    {
                        sGrade = "미";
                    }

                    strTmp += "\n" + "(" + sGrade + ")";

                    range.set_Value(Missing.Value, strTmp);

                    //순위
                    range = Util.OSheet.get_Range("M" + rowIndex.ToString(), Missing.Value);
                    double d = Double.Parse(suminfo[7].ToString());
                    string sRank = d.ToString() + " / " + DBUtil.getMTargetCount(getTargetType());

                    range.set_Value(Missing.Value, sRank);

                    rowIndex += 3;

                }

                lblMsg.Text = "서식 적용 중...";
                range = Util.OSheet.get_Range("A13", "O" + (rowIndex - 1).ToString());
                range.Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeBottom].Weight = Excel.XlBorderWeight.xlThin;
                range.Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeLeft].Weight = Excel.XlBorderWeight.xlThin;
                range.Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeRight].Weight = Excel.XlBorderWeight.xlThin;
                range.Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlInsideHorizontal].Weight = Excel.XlBorderWeight.xlThin;
                range.Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlInsideVertical].Weight = Excel.XlBorderWeight.xlThin;
                range = Util.OSheet.get_Range("A" + rowIndex, "O1000");
                range.Delete(Excel.XlDeleteShiftDirection.xlShiftUp);

                string myDocPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                string fileName = myDocPath + "\\tmp.xls";
                FileInfo f = new FileInfo(fileName);
                if (f.Exists)
                {
                    f.Delete();
                }

                Util.OWorkBook.SaveAs(fileName, Missing.Value, Config.xls_password, Missing.Value, true, Missing.Value, Excel.XlSaveAsAccessMode.xlShared, Excel.XlSaveConflictResolution.xlLocalSessionChanges, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                Util.OExcel.Visible = true;
                Util.OWorkBook.PrintPreview(Missing.Value);

                f.Delete();

                //lblMsg.Text = "인쇄합니다...";
                //PrintDialog dlg = new PrintDialog();
                //dlg.AllowSomePages = true;
                //dlg.AllowCurrentPage = true;
                //dlg.AllowPrintToFile = false;
                //dlg.PrinterSettings.Duplex = System.Drawing.Printing.Duplex.Vertical;
                //if (dlg.ShowDialog() == DialogResult.OK)
                //{
                //    int startPage = dlg.PrinterSettings.FromPage;
                //    int endPage = dlg.PrinterSettings.ToPage;
                //    Util.OSheet.PageSetup.CenterHorizontally = true;

                //    range = Util.OSheet.get_Range("A1", "O" + (rowIndex - 1).ToString());

                //    if (startPage > 0 && endPage > 0)
                //    {
                //        range.PrintOut(startPage, endPage, dlg.PrinterSettings.Copies, false, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                //    }
                //    else
                //    {
                //        range.PrintOut(Missing.Value, Missing.Value, dlg.PrinterSettings.Copies, false, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                //    }
                //}
                //dlg.Dispose();

                //Util.closeXls();

                lblMsg.Text = "";

                btnXls.Enabled = true;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Util.closeXls();
            }
        }

        private void btnDemerit_Click(object sender, EventArgs e)
        {

            if (dgvWMSum.Rows.Count == 1)
            {
                lblMsg.Text = "평정 및 확인 후 다시 시도하십시오.";
                return;
            }

            if (dgvWMSum.CurrentRow != null)
            {
                
                Form f = new FormDemerit(dgvWMSum, dgvWMSum.CurrentRow);
                f.ShowDialog();
            }
            else
            {
                MessageBox.Show("대상자를 선택하세요!    ", "확인", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }

        private void btnCalcByControl_Click(object sender, EventArgs e)
        {
            btnCalcByControl.Enabled = false;
            Thread t = new Thread(new ThreadStart(calcByControlPoint));
            t.Start();
        }

        private void calcByControlPoint()
        {
            int targetCount = DBUtil.getMTargetCount(getTargetType());
            try
            {
                if (dgvWMSum.Rows.Count < 2)
                {
                    lblMsg.Text = "*평정 및 확인 후 다시 시도하십시오.";
                    return;
                }

                double[] total = new double[targetCount];

                //조정점
                for (int i = 0; i < targetCount; i++)
                {
                    total[i] = Math.Round(Double.Parse(dgvWMSum.Rows[i].Cells[9].Value.ToString()), 2);
                    if (total[i] < 1.0)
                    {
                        lblMsg.Text = "*조정점이 없습니다.";
                        return;
                    }

                }

                //순위
                for (int i = 0; i < targetCount; i++)
                {
                    dgvWMSum.Rows[i].Cells[10].Value = Util.getSortNum(total, total[i]);
                }  

                //변동 사항 저장 여부 변경
                isSavedChange = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            btnCalcByControl.Enabled = true;
        }

        private void checkDemerit()
        {
            int nRow = tbl.Rows.Count;
                        
            for (int i = 0; i < nRow; i++)
            {
                string pcode = (string)tbl.Rows[i][2];

                if (DBUtil.existedDemeritData(pcode))
                {

                    dgvWMSum.Rows[i].DefaultCellStyle.BackColor = Color.YellowGreen;
                    
                }
                else
                {
                    dgvWMSum.Rows[i].DefaultCellStyle.BackColor = Color.FromArgb(240, 240, 240);
                }
            }
            
        }

        private byte getTargetType()
        {
            return (byte)parent.tscTargetType.SelectedIndex;
        }

    }
}
